package ltd.smallwang.infrastructure.task.db;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ltd.smallwang.infrastructure.task.db.model.TaskPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface TaskMapper extends BaseMapper<TaskPo> {

  @Select("""
select id, name, description, user_id, user_name, start_time, end_time, complete_flag, create_time, modify_time 
from schedule_self.task 
where start_time >= #{startTime} and end_time <= #{endTime};
""")
  List<TaskPo> queryTasksByStartTimeAndEndTime(@Param("startTime") LocalDateTime startTime,
      @Param("endTime") LocalDateTime endTime);

  @Select("""
select id, name, description, user_id, user_name, start_time, end_time, complete_flag, create_time, modify_time 
from schedule_self.task 
where start_time >= #{startTime};
""")
  List<TaskPo> queryTasksByStartTim(@Param("startTime") LocalDateTime startTime);

  @Update("""
update schedule_self.task set complete_time = null where id = #{id}
""")
  void clearCompleteTime(@Param("id") long id);
}
